﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using Main_Data;

namespace Category_UI
{
    public static class LocalValues
    {
        private static DataEntities _model;
        public static DataEntities Model
        {
            get
            {
                try
                {
                    string str = string.Empty;
                    try
                    {
                        str = ConfigurationManager.ConnectionStrings["DataEntities"].ConnectionString;
                    }
                    catch
                    {
                        throw new Exception("Model: can't get connect string");
                    }

                    if (_model == null)
                        _model = new DataEntities(str);
                    return _model;
                }
                catch (Exception ex)
                {
                    throw new Exception("Model: " + ex.Message);
                }
            }
        }

        public static void RefreshModel()
        {
            try
            {
                string str = string.Empty;
                try
                {
                    str = ConfigurationManager.ConnectionStrings["CategoryEntities"].ConnectionString;
                }
                catch
                {
                    throw new Exception("Model: can't get connect string");
                }

                if (_model == null)
                    _model = new DataEntities(str);
            }
            catch (Exception ex)
            {
                throw new Exception("Model: " + ex.Message);
            }
        }
    }
}
